package com.antunnel.system.web;

import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.antunnel.system.entity.UserBase;
import com.antunnel.system.service.LoginService;
import com.antunnel.system.service.UserBaseService;

@RequestMapping("/login")
@Controller(value="login")
public class LoginController {
	@Autowired
	UserBaseService userBaseService;
	@Autowired
	LoginService loginService;
	
	@RequestMapping(value = "loginIndex")
	public String loginIndex(String username, String password,
			PrintWriter out, HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
		UserBase userBase = userBaseService.loadUserByUserNameAndPsw(username,password);
		if(userBase!=null){
			Boolean  isExpired = loginService.checkUserLoginExpired(userBase.getActivetime());
			if(isExpired){
					//禁止登陆，前端提示超过14天不活跃，联系管理员	
			}else{
				session.setAttribute("loginUser",userBase);
			}
		
			return "main";
		}else{
			return "register";
		}
	}
}
